import 'package:flutter/material.dart';

class TaskItemComp extends StatefulWidget {
  TaskItemComp({super.key, required this.taskItem});
  Map taskItem;

  @override
  State<TaskItemComp> createState() => _TaskItemCompState();
}

class _TaskItemCompState extends State<TaskItemComp> {
  Map taskItem = {};

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    setState(() {
      taskItem = widget.taskItem;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(15),
      margin: EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        children: [
          // 任务编号
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                '任务编号: ${taskItem['id']}',
                textAlign: TextAlign.start,
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
              ),
            ],
          ),
          SizedBox(height: 20),
          // 起始地址
          Row(
            children: [
              // 起始地址图标
              PhysicalModel(
                color: Colors.transparent,
                elevation: 3, // 阴影高度
                shape: BoxShape.circle, // 直接指定圆形
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(50),
                  child: Container(
                    color: Colors.black, // 背景色
                    padding: EdgeInsets.all(5),
                    child: Text(
                      '起',
                      style: TextStyle(color: Colors.white, fontSize: 12),
                    ),
                  ),
                ),
              ),
              SizedBox(width: 12),
              // 右侧地址
              Expanded(
                child: Text(
                  '${taskItem['startAddress']}',
                  style: TextStyle(
                    fontSize: 14,
                    color: Color.fromARGB(255, 129, 129, 129),
                  ),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ],
          ),
          SizedBox(height: 15),
          // 终止地址
          Row(
            children: [
              // 起始地址图标
              PhysicalModel(
                color: Colors.transparent,
                elevation: 3, // 阴影高度
                shape: BoxShape.circle, // 直接指定圆形
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(50),
                  child: Container(
                    color: Colors.red, // 背景色
                    padding: EdgeInsets.all(5),
                    child: Text(
                      '止',
                      style: TextStyle(color: Colors.white, fontSize: 12),
                    ),
                  ),
                ),
              ),
              SizedBox(width: 12),
              // 右侧地址
              Expanded(
                child: Text(
                  '${taskItem['endAddress']}',
                  style: TextStyle(
                    fontSize: 14,
                    color: Color.fromARGB(255, 129, 129, 129),
                  ),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ],
          ),
          SizedBox(height: 30),
          //提货时间
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '提货时间',
                    style: TextStyle(
                      fontSize: 14,
                      color: Color.fromARGB(255, 129, 129, 129),
                    ),
                  ),
                  SizedBox(height: 5),
                  Text(
                    '${taskItem['planArrivalTime']}',
                    style: TextStyle(fontSize: 14),
                  ),
                ],
              ),
              // 提货
              ElevatedButton(
                onPressed: () {},
                style: ElevatedButton.styleFrom(
                  backgroundColor: taskItem['enablePickUp']
                      ? Colors.red
                      : Color.fromARGB(255, 250, 220, 217),
                  foregroundColor: Colors.white,
                ),
                child: Text('提货'),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
